package com.yunji.storage.pattern;

import com.yunji.storage.domain.StockDO;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.math.BigDecimal;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.storage.pattern
 * @Title: SaleInteract
 * <p>
 * History:
 * Date                     Version     Author          Summary
 * ============================================================
 * 2024-09-14 15:47:03      V1.0        HuaAo       新建类
 */
@Component
public class SaleInteract extends AbstractStorage {

    @Override
    protected void addStorage(StockDO stock) {
        logs.info("【销售入库】{}", stock);
    }

    @Override
    protected void subtractStock(StockDO stock) {
        BigDecimal actualQuantity = stock.get(OPERATE_NUMS);

        logs.info("【销售出库】出库个数:{}", actualQuantity);

        StockDO update = new StockDO();
        update.setBelongId(stock.getBelongId());
        update.setProductId(stock.getProductId());
        update.setFrozenStock(actualQuantity.negate());
        update.setAllStock(actualQuantity.negate());
        Assert.isTrue(stockService.updateStock(update), "出库失败");
    }

    @Override
    protected void backStock(StockDO stock) {
        logs.info("【销售出库】返还库存:{}", stock);
    }

    @Override
    protected void createBackStock(StockDO stock) {
        logs.info("【销售库存处理】新增销售库存:{}", stock);
    }

    @Override
    public void updateTicket(Long businessId) {
        logs.info("【更新单据】{}", businessId);
    }

    @Override
    public void checkTicket(String businessCode) {
        logs.info("【检查单据】{}", businessCode);
    }
}